<?php

namespace App\Models\PartTime;

use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use Illuminate\Database\Eloquent\Model;

/**
 * 兼职工作简历Model
 * Class PartTimeType
 * @package App\Models\PartTime
 */
class PartTimeResume extends Model
{
    //设置表的类型和表名
    protected $table = 'part_time_resume';
    protected $primaryKey = 'id';
    public $timestamps = true;
    protected $guarded = [];

    /**
     * 获取性别名称
     * @return false|string
     */
    public function getSexNameAttribute()
    {
        switch ($this->sex) {
            case '1':
                return '男';
                break;
            case '2':
                return '女';
                break;
        }
    }

    /**
     * 获取兼职工作空闲时间列表
     * @return mixed
     */
    public function getFreeTimeListAttribute()
    {
        return PartTimeResumeFreeTime::where('bt_id', '=', $this->id)->first();
    }

    /**
     * 获取是否学生要求名称
     * @return string
     */
    public function getStudentNameAttribute()
    {
        switch ($this->student) {
            case '0':
                return '在校学生';
                break;
            case '1':
                return '已经毕业';
                break;
        }
    }

    /**
     * 获取学历要求名称
     * @return string
     */
    public function getEducationNameAttribute()
    {
        if ($this->education == 0) {
            return '不限';
        } else {
            return CollOption::getOptionName($this->education, 'education');
        }
    }

    /**
     * 获取求职意向名称
     * @return string
     */
    public function getIntentionNameAttribute()
    {
        $intentionArray = explode(',', $this->intention);
        $string = '';
        foreach ($intentionArray as $k => $v) {
            $typeName = CollOption::getOptionName($v, 'part_time_type');
            if (strlen($string) != 0) {
                $string .= '，' . $typeName;
            } else {
                $string .= $typeName;
            }
        }
        return $string;
    }

    /**
     * 获取省市区信息-期望地点
     * @return string
     */
    public function getPlaceProvinceAreaCityAttribute()
    {
        return CollArea::getAreaAddress($this->place);
    }

    /**
     * 获取市区信息-期望地点
     * @return string
     */
    public function getPlaceAreaCityAttribute()
    {
        return CollArea::getCityAddress($this->place);
    }

    /**
     * 获取区信息-期望地点
     * @return string
     */
    public function getPlaceCityAttribute()
    {
        return CollArea::getAreaName($this->place);
    }

    /**
     * 获取省市区信息-居住地
     * @return string
     */
    public function getAddressProvinceAreaCityAttribute()
    {
        return CollArea::getAreaAddress($this->address);
    }

    /**
     * 获取市区信息-居住地
     * @return string
     */
    public function getAddressAreaCityAttribute()
    {
        return CollArea::getCityAddress($this->address);
    }

    /**
     * 获取区信息-居住地
     * @return string
     */
    public function getAddressCityAttribute()
    {
        return CollArea::getAreaName($this->address);
    }

    /**
     * 时间转换-在校开始时间-年月
     * @return string
     */
    public function getYMTimeStartAttribute()
    {
        return date('Y-m', strtotime($this->time_start));
    }

    /**
     * 时间转换-在校结束时间-年月
     * @return string
     */
    public function getYMTimeEndAttribute()
    {
        return date('Y-m', strtotime($this->time_end));
    }
}